<?php
class Logowanie{

	private $userlogin;
	
	function __construct(){
		try{
			$this->sign_in($_POST['login'], $_POST['haslo'], $_POST['kto']);
			print_r($_POST);
			if (empty($_SESSION["zalogowany"])) {
				$this->userlogin = false;
			} else {
				$this->userlogin = true;
				header("Location: main.php");
			}
		} catch(Exception $e) {
			print_r($e, 1);
		}
	}
 
  public function isLogged(){
	return $this->userlogin;
  }
	
	
	private function sign_in($login, $haslo, $kto) {
		if (isset($login)&& isset($haslo)){
			$tablica = explode('.', $login);
			$imie = $tablica[0];
			$nazwisko = $tablica[1];
			$sql = "SELECT * FROM $kto WHERE Imie='$imie' AND Nazwisko='$nazwisko' AND Haslo='$haslo'";
			//echo $sql;
			$wynik = mysql_query($sql) or die (mysql_error());					
				if(mysql_num_rows($wynik)){
						$dane = mysql_fetch_array($wynik);									
						$_SESSION["zalogowany"] = "tak";
						$_SESSION["kto"] = $kto;
						$_SESSION["id"] = $dane['Id'];	
						$_SESSION["login"] = $login;
				} else{					
					session_unset('zalogowany');
				}
		}
		return $zalogowany;
	}
}
?>